import {
	OptViewActionType,
	IOptViewAbility,
	IOptViewControllerParams,
	IOptViewModel,
	IOptViewStore,
	IParam,
	IViewEvent,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
	getViewClassNames,
	handleOptViewButtonAction,
	useViewAction,
	useViewBasic,
	useViewControllerParams,
	useViewProps,
} from '../use-view';

/**
 * 获取选项操作视图输入参数
 *
 * @export
 * @return {*}
 */
export function useOptViewProps() {
	return {
		...useViewProps(),
	};
}

/**
 * 获取选项操作视图基础
 *
 * @export
 * @param {IOptViewModel} model 选项操作视图模型
 * @param {IParam} props 输入参数
 * @return {*}
 */
export function useOptViewBasic(model: IOptViewModel, props: IParam) {
	const getClassNames = (props: IParam) => {
		return getViewClassNames(model, props);
	};
	return {
		...useViewBasic(model, props),
		getClassNames,
		handleOptViewButtonAction,
	};
}

/**
 * 选项操作视图行为
 *
 * @export
 */
export function useOptViewAction(controller: any) {
	const handleConfirm = () => {
		controller.confirm();
	};
	const handleCancel = () => {
		controller.cancel();
	};
	return {
		...useViewAction(controller),
		handleConfirm,
		handleCancel,
	};
}

/**
 * 获取选项操作视图控制器输入参数
 *
 * @export
 * @param {IOptViewModel} model
 * @param {IParam} props
 * @param {QXEvent<IViewEvent<OptViewActionType, IOptViewAbility>>} evt
 * @return {*}  {IOptViewControllerParams<OptViewActionType, IOptViewAbility>}
 */
export function useOptViewControllerParams(
	model: IOptViewModel,
	props: IParam,
	evt: QXEvent<IViewEvent<OptViewActionType, IOptViewAbility>>
): IOptViewControllerParams<OptViewActionType, IOptViewAbility> {
	return {
		...useViewControllerParams<IOptViewStore, IOptViewModel>(model, props, evt),
	};
}
